/**
 * This software implements a CAT-1 LTE baseband.
 *
 * Copyright (C) 2015  Optimum Semiconductor Technologies, Inc. info@optimumsemi.com
 *
 * lte_trch.c --
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.

 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 */

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
/*                                                                          */
/* floating point C code for LTE uplink -- appears to have been adapted     */
/*  from a C file of the same name in the LTE downlink directory            */
/*                                                                          */
/* This code is called from (many) Matlab mexFunction(s) and is the underlying*/
/* implementation for the Matlab implementation of the uplink model for     */
/* the PUSCH channel                                                        */
/*                                                                          */
/* e.g. Turbo was exactly the same except for cosmetic changes              */
/*                                                                          */
/* Documented 2012/07/31 -- AJH                                             */
/*                                                                          */
/* discovered                                                               */
/*             nc === num_code_blocks                                       */
/*             nf === num_filler_bits                                       */
/*                                                                          */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/

#include "lte_trch.h"


/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
/*                                                                          */
/* tb_conv  -- Tail biting convolutional encoder/decoder -- used for control*/
/*  information coding                                                      */
/*                                                                          */
/* This should be from 36.212, although I didn't check -- AJH               */
/*                                                                          */
/* 36.212 Figure 5.1.3-1                                                    */
/*                                                                          */
/* "Constraint length 7 and coding rate 1/3"                                */
/*                                                                          */
/* Ck ---> D  ---->  D  ---->  D  ---->  D  ----> D -----> D ----           */
/*     |        ||       |||       ||         |       |       |||           */
/*     |        ||       |||       ||         |       |       |||           */
/*     |--------||-------+||-------+|---------|-------+-------+||-->Dk0===0133 */
/*     |        ||        ||        |         |                ||           */
/*     |        ||        ||        |         |                ||           */
/*     |--------+|--------+|--------+---------|----------------+|-->Dk1===0171 */
/*     |         |         |                  |                 |           */
/*     |         |         |                  |                 |           */
/*     |---------+---------+------------------+-----------------+-->Dk2===0165 */
/*                                                                          */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
void tb_conv(char *in, int input_len, char *out) 
{

  char reg[6];
  int i,j;

  for(i=0;i<6;i++) reg[i] = in[input_len-1-i];

  for(i=0;i<input_len;i++){
    out[i]             = in[i]^reg[1]^reg[2]^reg[4]^reg[5];
    out[i+input_len]   = in[i]^reg[0]^reg[1]^reg[2]^reg[5];
    out[i+2*input_len] = in[i]^reg[0]^reg[1]^reg[3]^reg[5];
    /*seperate coded bits for rate matching.*/

    for(j=5;j>0;j--) reg[j]=reg[j-1];
    reg[0]=in[i];
    }

//  return;
}
